import { createElement } from 'react';
import dynamic from 'dva/dynamic';
// import pathToRegexp from 'path-to-regexp';
import { workStationRoutes } from './workStationRouter'; // 工作台路由地址

let routerDataCache;
// 判断model是否已经被注入
const modelNotExisted = (app, model) =>
  !app._models.some(({ namespace }) => {
    return namespace === model.substring(model.lastIndexOf('/') + 1);
  });
// 注入model和路由组件
const dynamicWrapper = (app, models, component) => {
  if (component.toString().indexOf('.then(') < 0) {
    // 通过models，每个路由单独注入models,但因为我们采取统一从src/index.js里注入model，这里传入的models都为空数组
    // 且因为models现在有两个文件夹，此函数没有兼容，所以下次如果想启用这里的注入，这里必须需要修改才可用
    models.forEach((model) => {
      if (modelNotExisted(app, model)) {
        app.model(require(`../models/${model}`).default);
      }
    });
    return (props) => {
      if (!routerDataCache) {
        routerDataCache = getRouterData(app);
      }
      return createElement(component().default, {
        ...props,
        routerData: routerDataCache,
      });
    };
  }
  return dynamic({
    app,
    models: () => models.filter((model) => modelNotExisted(app, model)).map((m) => import(`../models/${m}.js`)),
    // 注入路由信息和props
    component: () => {
      if (!routerDataCache) {
        routerDataCache = getRouterData(app);
      }
      return component().then((raw) => {
        const Component = raw.default || raw;
        return (props) =>
          createElement(Component, {
            ...props,
            routerData: routerDataCache,
          });
      });
    },
  });
};

// function getFlatMenuData(menus) {
//   let keys = {};
//   menus.forEach((item) => {
//     if (item.children) {
//       keys[item.path] = { ...item };
//       keys = { ...keys, ...getFlatMenuData(item.children) };
//     } else {
//       keys[item.path] = { ...item };
//     }
//   });
//   return keys;
// }

// 合并工作台相关路由地址
const menuUrl = [].concat(
  workStationRoutes.map((item) => {
    item.url = item.path;
    return item;
  }),
);
const getRouterData = (app) => {
  // 主功能对应的路由
  const routerConfig = {
    // 主框架页面
    '/': {
      component: dynamicWrapper(app, [], () => import('../layouts/BasicLayout')),
      permission: true,
    },

    // 首页
    '/mainCalendar': {
      component: dynamicWrapper(app, [], () => import('../routes/userView')),
      // component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/CalendarNew')),
      name: '首页',
      permission: true,
    },
    // 用户视图
    // '/mainCalendar1': {
    //   component: dynamicWrapper(app, [], () => import('../routes/userView')),
    //   name: '用户视图',
    //   permission: true,
    // },

    // 新闻详情-自动跳转到主体舆情监控
    '/marketAnalysis/Monitorpublicopinion/newsDetail': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/mon/monDetail/newsDetail')),
      name: '新闻详情',
      permission: true,
    },

    // 公告详情-自动跳转到主体舆情监控
    '/marketAnalysis/Monitorpublicopinion/noticeDetail': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/mon/monDetail/noticeDetail')),
      name: '公告详情',
      permission: true,
    },

    // 登录页面
    // '/user': {
    //   component: dynamicWrapper(app, [], () => import('../routes/login/login')),
    //   permission: true

    // },

    // demo页面
    // '/demo': {
    //   component: dynamicWrapper(app, [], () => import('../demo')),
    // },

    // 运维表格
    // '/operation': {
    //   component: dynamicWrapper(app, [], () => import('../operation')),
    // },
    /** -----------------顶部工具栏跳转----------------- */
    // 待办任务从右上角跳转
    '/taskInfoList': {
      component: dynamicWrapper(app, [], () => import('../routes/agencyTask')),
      name: '待办任务',
      permission: true,
    },

    // 审批信息-从各审批页面或代办页面跳转
    '/agencyTask/autoPool': {
      component: dynamicWrapper(app, [], () => import('../routes/agencyTask/approval')),
      name: '审批信息',
      permission: true,
    },
    // 历史公告查询 从右上角跳转
    '/systemHistoryNotice': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/systemNoticeSetting/histotyIndex')),
      name: '历史公告查询',
      permission: true,
    },

    // 债券信息-从右上角债券搜索框跳转
    '/marketAnalysis/bondDeviationDetail': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/bondDeviationAnalysis/bondDeviationDetail')),
      name: '债券信息',
      permission: true,
    },

    /** -----------------工作台------------------ */

    // 工作台
    '/OperatePlatform': {
      component: dynamicWrapper(app, [], () => import('../routes/OperatePlatform')),
      name: '工作台',
    },
    // 工作台跳转
    '/OperatePlatform/taskDidList': {
      component: dynamicWrapper(app, [], () => import('../routes/OperatePlatform/taskDidList')),
      name: '已办任务',
      permission: true,
    },
    // 工作台跳转
    '/OperatePlatform/convertibleBondList': {
      component: dynamicWrapper(app, [], () => import('../routes/OperatePlatform/convertibleBondList')),
      name: '可转债赎回',
    },
    // 工作台跳转
    '/OperatePlatform/BondAbnormal': {
      component: dynamicWrapper(app, [], () => import('../routes/OperatePlatform/BondAbnormal')),
      name: '债券价格异常提醒',
    },
    // 工作台跳转
    '/OperatePlatform/BackSellRegister': {
      component: dynamicWrapper(app, [], () => import('../routes/OperatePlatform/BackSellRegister')),
      name: '回售登记提醒',
    },
    // 工作台跳转
    '/OperatePlatform/ExerciseRemind': {
      component: dynamicWrapper(app, [], () => import('../routes/OperatePlatform/ExerciseRemind')),
      name: '行权提醒',
    },

    /** -----------------菜单管理------------------ */

    // 菜单管理
    '/menuManage': {
      component: dynamicWrapper(app, [], () => import('../routes/MenuManage/MenuManage')),
      name: '菜单管理',
    },
    /** -----------------资产拆分------------------ */
    // 资产拆分/系列产品管理
    '/assetSplit/seriesProductManage': {
      component: dynamicWrapper(app, [], () => import('../routes/assetSplit/seriesProductManage')),
      name: '系列产品管理',
    },
    // 资产拆分/存续管理
    '/assetSplit/survivalManage': {
      component: dynamicWrapper(app, [], () => import('../routes/assetSplit/SurvivalManageNew')),
      name: '存续管理',
    },
    // 资产拆分/拆分持仓查询
    '/assetSplit/SplitPositionQuery': {
      component: dynamicWrapper(app, [], () => import('../routes/assetSplit/SplitPositionQuery')),
      name: '拆分持仓查询',
    },
    // 资产拆分/拆分流水查询
    '/assetSplit/SplitPipelineQuery': {
      component: dynamicWrapper(app, [], () => import('../routes/assetSplit/SplitPipelineQuery')),
      name: '拆分流水查询',
    },

    /** -----------------市场分析------------------ */
    // 市场分析/主体监控舆情
    '/marketAnalysis/Monitorpublicopinion': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/mon')),
      name: '主体舆情监控',
    },
    // 市场分析/债券评级监控
    '/marketAnalysis/Ratingmonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/monitorRatingNew')),
      name: '债券评级监控',
    },
    // 市场分析/我的关注
    '/marketAnalysis/Myattention': {
      component: dynamicWrapper(app, [], () => import('../routes/MyAttention')),
      name: '我的关注',
    },
    // 场分析/债券偏离度监控/日终偏离监控
    '/marketAnalysis/bondDeviationMonitoring/dayEndDeviationMonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/BondDeviationMonitoring/DayEndDeviationMonitoring')),
      name: '日终偏离监控',
    },
    // 市场分析/债券偏离度监控/实时偏离监控
    '/marketAnalysis/bondDeviationMonitoring/bondDeviationAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/marketAnalysis/bondDeviationAnalysis')),
      name: '实时偏离监控',
    },

    /** -----------------券池管理------------------ */

    // 券池管理/券池定义
    '/securityMnt/couponPoolDefinition': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentResearch/securityMnt/couponPoolDefinition/CouponPoolDefinition')),
      name: '券池定义',
    },
    // 券池管理/券池查询-债券
    '/securityMnt/couponPoolQuery/bond': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentResearch/securityMnt/couponPoolQuery/bond/Bond')),
      name: '券池查询',
    },
    // 券池管理/券池查询-股票
    '/securityMnt/couponPoolQuery/stock': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentResearch/securityMnt/couponPoolQuery/bond/Bond')),
      name: '券池查询',
    },
    // 券池管理/券池查询-基金
    '/securityMnt/couponPoolQuery/fund': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentResearch/securityMnt/couponPoolQuery/bond/Bond')),
      name: '券池查询',
    },
    // 券池管理/券池审批
    '/securityMnt/couponPoolApproval': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentResearch/securityMnt/couponPoolApproval')),
      name: '券池审批',
    },
    // 券池管理/券池审批页面跳转
    '/securityMnt/autoMonitor': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentResearch/securityMnt/couponPoolApproval/autoMonitor')),
      name: '自动入池监控',
      permission: true,
    },

    /** -----------------交易对手管理------------------ */

    // 交易对手管理/交易对手基础信息
    '/counterpartyManagement/counterpartyInformation': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/counterpartyInformation')),
      name: '交易对手基础信息',
    },
    // 交易对手管理/交易对手基础信息-新增按钮跳转
    '/counterpartyManagement/counterpartyInfoAdd': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/counterpartyInformation/counterpartyInfoAdd')),
      name: '新增交易对手',
      permission: true,
    },
    // 交易对手管理/交易对手基础信息-修改按钮跳转
    '/counterpartyManagement/counterpartyInfoEdit': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/counterpartyInformation/counterpartyInfoEdit')),
      name: '编辑交易对手',
      filter: '/counterpartyManagement/counterpartyInfoEdit',
      permission: true,
    },
    // 交易对手管理/交易对手基础信息-查看按钮跳转
    '/counterpartyManagement/counterpartyInfoQuery': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/counterpartyInformation/counterpartyInfoQuery')),
      name: '交易对手详情',
      permission: true,
    },
    // 交易对手管理/交易对手黑名单管理
    '/counterpartyManagement/blackList': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/personnelManagement/BlackList')),
      name: '交易对手黑名单管理',
    },
    // 交易对手管理/交易对手白名单管理
    '/counterpartyManagement/whiteList': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/personnelManagement/WhiteList')),
      name: '交易对手白名单管理',
    },
    // 交易对手管理/交易对手授信额度管理/授信设置
    '/counterpartyManagement/creditLineManagement/creditSetting': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/creditLineManagement/creditSetting')),
      name: '授信设置',
    },
    // 交易对手管理/交易对手授信额度管理/授信占用监控
    '/counterpartyManagement/creditLineManagement/creditOccupation': {
      component: dynamicWrapper(app, [], () => import('../routes/counterpartyManagement/creditLineManagement/creditOccupation')),
      name: '授信占用监控',
    },

    /** -----------------限额管理------------------ */
    '/riskMonitor/limitManagemenNew': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentMonitor/limitSettingNew')),
      name: '限额设置（新）',
    },
    // 限额管理/限额设置
    '/riskMonitor/limitManagemen': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentMonitor/limitSetting')),
      name: '限额设置',
    },
    // 限额管理/限额监控
    '/riskMonitor/limitMonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentMonitor/LimitMonitoring')),
      name: '限额监控',
    },
    // 限额管理/限额触警查询
    '/riskMonitor/limitAlarmquery': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentMonitor/limitAlarmquery')),
      name: '限额触警查询',
    },

    /** -----------------组合管理------------------ */

    // 组合管理/组合定义
    '/portfolioBuild/portfolioTreeMnt': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/portfolioDefinition')),
      name: '组合定义',
    },
    // 组合管理/现金流管理/现金流预测
    '/portfolioBuild/cashManage/forecast': {
      component: dynamicWrapper(app, [], () => import('../routes/cashManage/forecast')),
      name: '现金流预测',
    },
    // 组合管理/现金流管理/现金流回溯
    '/portfolioBuild/cashManage/backtracke': {
      component: dynamicWrapper(app, [], () => import('../routes/cashManage/backtracke')),
      name: '现金流回溯',
    },
    // 组合管理/组合日历
    '/portfolioBuild/investmentCalendar': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/CalendarNew')),
      name: '组合日历',
    },
    // 组合管理/组合试算
    '/portfolioBuild/portfolioTrial': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioTrialR')),
      name: '组合试算',
    },
    // 组合管理/产品组定义
    'SystemManagement/productGroupDefinition': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/portfolioManage')),
      name: '产品组定义',
      permission: true,
    },
    // 组合管理/组合跟踪
    '/portfolioBuild/portfolioTracking': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/portfolioTrackings')),
      name: '组合跟踪',
    },
    // 组合管理/组合优化
    '/portfolioBuild/PortfolioOptimization': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/portfolioOptimization')),
      name: '组合优化',
    },
    // 组合管理/指数监控
    '/portfolioBuild/indexMonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/indexMonitoring')),
      name: '指数监控',
    },
    // 组合管理/资产筛选
    '/portfolioBuild/AssetPreparation': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/AssetPreparation')),
      name: '资产筛选',
    },

    /** -----------------投资建议书------------------ */
    // 投资建议书/建议书查询
    '/proposal/proposalList': {
      component: dynamicWrapper(app, [], () => import('../routes/businessProposal/EtfTradeNew/TradeSearch/TradeSearch')),
      name: '建议书查询',
    },
    // 投资建议书/基金建议书
    '/proposal/etfProposal': {
      component: dynamicWrapper(app, [], () => import('../routes/businessProposal/EtfTradeNew')),
      name: '基金建议书',
    },
    // 投资建议书/建议书审批
    '/proposal/proposalVerify': {
      component: dynamicWrapper(app, [], () => import('../routes/businessProposal/Approval')),
      name: '建议书审批',
    },

    /** -----------------指令下达------------------ */

    // 指令下达/指令查询
    '/tradeInstruction/tradeInstructionQuery': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/newTrade')),
      name: '指令查询',
    },
    // 指令下达/债券指令
    '/tradeInstruction/bondTrade': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/BondTradeNew')),
      name: '债券指令',
    },
    // 指令下达/回购指令
    '/tradeInstruction/buybackOrder': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/BuybackOrder/index1')),
      name: '回购指令',
    },
    // 指令下达/基金指令
    '/tradeInstruction/etfTrade': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/EtfTradeNew/etfTrade')),
      name: '基金指令',
    },
    // 指令下达/股票指令
    '/tradeInstruction/stockOrder': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/StockOrder/stockIndex')),
      name: '股票指令',
    },

    /** -----------------交易簿记------------------ */

    // 交易簿记/簿记查询
    '/transactions/bookkeepingManagement': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/BookkeepingMnt')),
      name: '簿记查询',
    },
    // 交易簿记/多产品簿记
    '/transactions/moreFundsOrder': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/moreFundsOrder')),
      name: '多产品簿记',
    },
    // 交易簿记/债券簿记/二级现券簿记
    '/transactions/bond/secondBond': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/bond')),
      name: '二级现券簿记',
    },
    // 交易簿记/债券簿记/一级申购簿记
    '/transactions/bond/offlineOrder': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/offlineOrder')),
      name: '一级申购簿记',
    },

    // 交易簿记/基金簿记/场外基金簿记
    '/transactions/fundBookkeeping/fundTrade': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/fundTrade')),
      name: '场外基金簿记',
    },
    // 交易簿记/基金簿记/场内（ETF）基金簿记
    '/transactions/fundBookkeeping/ETF': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/ETF')),
      name: '场内（ETF）基金簿记',
    },

    // 交易簿记/股票簿记/A股簿记
    '/transactions/stock/Astock': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/stock')),
      name: 'A股簿记',
    },
    // 交易簿记/股票簿记/港股通簿记
    '/transactions/stock/addHK': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/addHK')),
      name: '港股通簿记',
    },
    // 交易簿记/非标簿记/理财直融簿记
    '/transactions/nonstandard/finaFlocking': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/finaFlocking')),
      name: '理财直融簿记',
    },
    // 交易簿记/非标簿记/非理财直融簿记
    '/transactions/nonstandard/falseFinaFlocking': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/nonstandard')),
      name: '非理财直融簿记',
    },
    // 交易簿记/回购簿记
    '/transactions/buyBack': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/buyBack')),
      name: '回购簿记',
    },
    // 交易簿记/存款簿记
    '/transactions/deposit': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/deposit')),
      name: '存款簿记',
    },
    // 交易簿记/债券借贷簿记
    '/transactions/bondLend': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/bondLend')),
      name: '债券借贷簿记',
    },
    // 交易簿记/资产管理计划簿记
    '/transactions/assets': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/assets')),
      name: '资产管理计划簿记',
    },
    // 交易簿记/委外投资簿记
    '/transactions/outInvestment': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/transactions/outInvestment')),
      name: '委外投资簿记',
    },
    // 交易簿记/期货簿记
    '/transactions/stockIndexFutures': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/StockIndexFutures')),
      name: '期货簿记',
    },

    /** -----------------运营管理------------------ */

    // 运营管理/交收管理
    '/OperationManagement/bookkeepingSettlement': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/BookkeepingSettle')),
      name: '交收管理',
    },
    // 运营管理/SPPI测试记录
    '/OperationManagement/sppiTestRecord': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/sppiTestRecord')),
      name: 'SPPI测试记录',
    },
    // 运营管理/多基金划款
    '/OperationManagement/multiFundDivision': {
      component: dynamicWrapper(app, [], () => import('../routes/InventoryMnt/multiFundDivision')),
      name: '多基金划款',
    },
    // 运营管理/股票组合指令
    '/OperationManagement/stockGroupOrder': {
      component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/stockGroupOrder')),
      name: '股票组合指令',
    },

    /** -----------------风险分析------------------ */

    // 风险分析/流动性风险
    '/riskAnalysis/liquidityRisk': {
      component: dynamicWrapper(app, ['liquidityRiskM'], () => import('../routes/riskAnalysis/liquidityRisk')),
      name: '流动性风险',
    },
    // 风险分析/VaR/VaR分析
    '/riskAnalysis/VaR/VarAnalysis': {
      component: dynamicWrapper(app, ['liquidityRiskM'], () => import('../routes/riskAnalysis/VaR/VarAnalysis')),
      name: 'VaR分析',
    },
    // 风险分析/市场风险/权益行业风险分析
    '/riskAnalysis/marketRisk/equityIndustryRisk': {
      component: dynamicWrapper(app, [], () => import('../routes/riskAnalysis/marketRisk/equityIndustryRisk')),
      name: '权益行业风险分析',
    },
    // 风险分析/市场风险/关键利率久期
    '/riskAnalysis/marketRisk/keyRateDurations': {
      component: dynamicWrapper(app, [], () => import('../routes/riskAnalysis/marketRisk/keyRateDurations')),
      name: '关键利率久期',
    },
    // 风险分析/风险归因
    '/riskAnalysis/riskAttribution': {
      component: dynamicWrapper(app, [], () => import('../routes/riskAnalysis/riskAttribution')),
      name: '风险归因',
    },

    /** -----------------绩效分析------------------ */

    // 绩效分析/交易分析
    '/performanceAnalysis/tradeAnalysisNew': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/tradeAnalysisNew')),
      name: '交易分析',
      filter: '/performanceAnalysis/tradeAnalysis',
    },
    // 绩效分析/净值分析
    '/performanceAnalysis/netValueAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/netValueAnalysis2')),
      name: '净值分析',
      // filter: '/performanceAnalysis/netValueAnalysis',
    },
    // 绩效分析/盈亏分析
    '/performanceAnalysis/profitAndLossAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/profitAndLossAnalysis/anysis')),
      name: '盈亏分析',
    },
    // 绩效分析/收益率表现
    '/performanceAnalysis/yieldPerformance': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/yiledPerformance')),
      name: '收益率表现',
    },
    // 绩效分析/归因分析
    '/performanceAnalysis/attributionAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/attributionAnalysis')),
      name: '归因分析',
    },
    // 绩效分析/组合概览
    '/performanceAnalysis/profitOverview': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/profitOverview')),
      name: '组合概览',
    },
    // 绩效分析/资产配置
    '/performanceAnalysis/assetDeploy': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/assetAllocation')),
      name: '资产配置',
    },
    // 绩效分析/绩效分析报告
    '/performanceAnalysis/performanceAnalysisReport': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysisReport')),
      name: '绩效分析报告',
    },

    /** -----------------资产定价------------------ */

    // 资产定价/非标估值复核
    '/assetPricing/nonstandardValueReview': {
      component: dynamicWrapper(app, [], () => import('../routes/repertoryManagement/nonstandardValueReview')),
      name: '非标估值复核',
    },
    // 资产定价/非标曲线映射
    '/assetPricing/nonstandardCurveMap': {
      component: dynamicWrapper(app, [], () => import('../routes/Product/nonstandardCurveMap')),
      name: '非标曲线映射',
    },

    /** -----------------库存管理------------------ */

    // 库存管理/估值核对
    '/inventoryMnt/positionCompare': {
      component: dynamicWrapper(app, [], () => import('../routes/InventoryMnt/HoldPosition/valuationCheck')),
      name: '估值核对',
    },
    // 库存管理/持仓管理
    '/inventoryMnt/positionManage': {
      component: dynamicWrapper(app, [], () => import('../routes/InventoryMnt/HoldPosition/PositionManageNew')),
      name: '持仓管理',
    },
    // 库存管理/资金管理
    '/inventoryMnt/fundManagement': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentAndDecision/FundManagement')),
      name: '资金管理',
    },
    // 库存管理/TA数据导入
    '/inventoryMnt/TADataImport': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioMnt/DataImportNew')),
      name: 'TA数据导入',
    },

    /** -----------------综合查询------------------ */

    // 综合查询/持仓查询
    '/composite/positionquery': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentAndDecision/PositionInquiry')),
      name: '持仓查询',
    },
    // 综合查询/流水查询
    '/composite/tansactionRecord': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentAndDecision/TansactionRecordquiry')),
      name: '流水查询',
    },
    // 综合查询/资金明细
    '/composite/financialDetails': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentAndDecision/capitalDetails')),
      name: '资金明细',
    },
    // 综合查询/信用账户资金明细
    '/composite/creditAccountDetail': {
      component: dynamicWrapper(app, [], () => import('../routes/investmentAndDecision/creditAccountDetail')),
      name: '信用账户资金明细',
    },

    /** -----------------系统管理------------------ */
    // 系统管理/跑批管理
    '/SystemManagement/runOffManage': {
      component: dynamicWrapper(app, [], () => import('../routes/SystemSetting/BatchManage')),
      name: '跑批管理',
    },
    // 系统管理/产品管理
    '/SystemManagement/productManage': {
      component: dynamicWrapper(app, [], () => import('../routes/Product/productManageNew')),
      name: '产品管理',
    },
    // 系统管理/估值解析
    '/SystemManagement/valuationAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/valuationAnalysis')),
      name: '估值解析',
    },

    // 系统管理/资产信息维护/债券发行维护
    '/SystemManagement/businessMaintenance/bondInformation': {
      component: dynamicWrapper(app, [], () => import('../routes/Product/bondInformation')),
      name: '债券发行维护',
    },
    // 系统管理/资产信息维护/非标(非理财直融)维护
    '/SystemManagement/businessMaintenance/nonstandarmaintenance': {
      component: dynamicWrapper(app, [], () => import('../routes/Product/nonstandarmaintenanceNew')),
      name: '非标(非理财直融)维护',
    },
    // 系统管理/资产信息维护/非标(理财直融)维护
    '/SystemManagement/businessMaintenance/directFinancingInformationMaintenance': {
      component: dynamicWrapper(app, [], () => import('../routes/Product/moneyInformation')),
      name: '非标(理财直融)维护',
    },
    // 系统管理/资产信息维护/委外投资维护
    '/SystemManagement/businessMaintenance/outsourceInvestMsgMaintain': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/outsourceInvestMsgMaintain')),
      name: '委外投资维护',
    },
    // 系统管理/资产信息维护/资产管理计划维护
    '/SystemManagement/businessMaintenance/assetManagementPlanMaintenance': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/qualificationManagementPlanMaintenance')),
      name: '资产管理计划维护',
    },
    // 系统管理/基准管理
    '/SystemManagement/baselineInformation': {
      component: dynamicWrapper(app, [], () => import('../routes/businessMaintenance/BaselineInformationNew/BaselineInformationNew')),
      name: '基准管理',
    },
    // 系统管理/存款账户管理/存款银行管理
    '/SystemManagement/depositAccountManagement/headOffice': {
      component: dynamicWrapper(app, [], () => import('../routes/DepositAccountManagement/headOffice')),
      name: '存款银行管理',
    },
    // 系统管理/存款账户管理/存款账号管理
    '/SystemManagement/depositAccountManagement/depositAccountNumberManagement': {
      component: dynamicWrapper(app, [], () => import('../routes/DepositAccountManagement/accountNumber/accountNumber')),
      name: '存款账号管理',
    },
    // 系统管理/日历管理
    '/SystemManagement/SystemCalendar': {
      component: dynamicWrapper(app, [], () => import('../routes/performanceAnalysis/SystemCalendar')),
      name: '日历管理',
    },
    // 系统管理/日志审计
    '/SystemManagement/auditLog': {
      component: dynamicWrapper(app, [], () => import('../routes/auditLog/auditLog')),
      name: '日志审计',
    },
    // 系统管理/费用维护
    '/SystemManagement/costMaintain': {
      component: dynamicWrapper(app, [], () => import('../routes/DepositAccountManagement/costMaintain')),
      name: '费用维护',
    },
    // 系统管理/文件上传
    '/SystemManagement/fileUpload': {
      component: dynamicWrapper(app, [], () => import('../routes/fileUpload')),
      name: '文件上传',
    },
    // 系统管理/系统公告设置
    '/SystemManagement/systemNoticeSetting': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/systemNoticeSetting')),
      name: '系统公告设置',
    },
    // 系统管理/系统视频管理
    '/SystemManagement/systemVedio': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/systemVedio')),
      name: '系统视频管理',
    },
    // 系统管理/汇率管理
    '/SystemManagement/exchangeRateMsgMaintain': {
      component: dynamicWrapper(app, [], () => import('../routes/systemManagement/exchangeRateMsgMaintain')),
      name: '汇率管理',
    },

    /** -----------------用户管理------------------ */

    // 用户管理/机构配置
    '/userManage/institutionConfiguration': {
      component: dynamicWrapper(app, [], () => import('../routes/UserManage/InstitutionConfiguration')),
      name: '机构配置',
    },
    // 用户管理/岗位配置
    '/userManage/Station': {
      component: dynamicWrapper(app, [], () => import('../routes/UserManage/Station/Station')),
      name: '岗位配置',
    },
    // 用户管理/角色配置
    '/userManage/role': {
      component: dynamicWrapper(app, [], () => import('../routes/UserManage/Role/Role')),
      name: '角色配置',
    },
    // 用户管理/用户配置
    '/userManage/user': {
      component: dynamicWrapper(app, [], () => import('../routes/UserManage/UserManageNew/UserManageNew')),
      name: '用户配置',
    },
    // 用户管理/租户配置
    '/userManage/tenant': {
      component: dynamicWrapper(app, [], () => import('../routes/UserManage/TenantManage/TenantManage')),
      name: '租户配置',
    },

    /** -----------------流程管理------------------ */

    // 流程管理/工作流管理
    '/ProcessManagement/Workflowmanagement': {
      component: dynamicWrapper(app, [], () => import('../routes/system/workFlow')),
      name: '工作流管理',
    },
    // 流程管理/流程查询
    '/ProcessManagement/ProcessQuery': {
      component: dynamicWrapper(app, [], () => import('../routes/processManagement/processQuery')),
      name: '流程查询',
    },

    /** -----------------运营监控------------------ */

    // 运营监控/交易监控
    '/OperationalMonitoring/TransactionMonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/OperationalMonitoring/TransactionMonitoring')),
      name: '交易监控',
    },
    // 运营监控/访问统计
    '/OperationalMonitoring/visitStatistics': {
      component: dynamicWrapper(app, [], () => import('../routes/OperationalMonitoring/visitStatistics')),
      name: '访问统计',
    },
    // 运营监控/运营总况
    '/OperationalMonitoring/operationOverall': {
      component: dynamicWrapper(app, [], () => import('../routes/OperationalMonitoring/operationOverall')),
      name: '运营总况',
    },
    // 运营监控/机构产品分析
    '/OperationalMonitoring/organProductAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/OperationalMonitoring/organProductAnalysis')),
      name: '机构产品分析',
    },

    /** -----------------报告服务------------------ */

    // 报告服务/现金管理理财新规报告
    '/reportingServices/cashManagementReport': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/cashManagementReport')),
      name: '现金管理理财新规报告',
    },
    // 报告服务/商业银行管理报告
    '/reportingServices/commercialBankManagementReport': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/commercialBankManagementReport')),
      name: '商业银行管理报告',
    },
    //
    // 报告服务/投顾报告
    '/reportingServices/investmentAdviserReport': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/InvestmentAdviserReport')),
      name: '投顾报告',
    },
    // 报告服务/人行监管报表信息维护
    '/reportingServices/bankSuperviseInfo': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/manBankReport')),
      name: '人行监管报表信息维护',
    },
    // 报告服务/非标类产品分析报告
    '/reportingServices/nonstandardReport': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/nonstandardReport')),
      name: '非标类产品分析报告',
    },
    // 报告服务/穿透持仓查询
    '/reportingServices/positionThroughQuery': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/positionThroughQuery')),
      name: '穿透持仓查询',
    },
    // 报告服务/限额穿透报表
    '/reportingServices/limitThroughReport': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/limitThroughReport')),
      name: '限额穿透报表',
    },
    // 报告服务/穿透持仓查询
    '/reportingServices/positionThroughQueryNew': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/positionThroughQuery/index1')),
      name: '穿透持仓查询(新)',
    },
    '/reportingServices/limitThroughReportNew': {
      component: dynamicWrapper(app, [], () => import('../routes/reportingServices/limitThroughReportNew')),
      name: '限额穿透报表（新）',
    },

    /** -----------------场外衍生品管理------------------ */

    // 场外衍生品管理/期权管理
    '/OTCDerivativesManagement/OptionManagement': {
      component: dynamicWrapper(app, [], () => import('../routes/shareOptionManagement')),
      name: '期权管理',
    },
    // 场外衍生品管理/场外期权生命周期管理
    '/OTCDerivativesManagement/lifeCycleManagementOfOTC': {
      component: dynamicWrapper(app, [], () => import('../routes/shareOptionManagement/OTCOptionLifeCycleManagement')),
      name: '场外期权生命周期管理',
    },
    // 场外衍生品管理/场外期权风险管理/场外期权存续合约监控
    '/OTCDerivativesManagement/riskManagementOfOTCOption/OTCOptionContractsMonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/shareOptionManagement/OTCOptionContractsMonitoring')),
      name: '场外期权存续合约监控',
    },
    // 场外衍生品管理/场外期权风险管理/场外期权压力测试
    '/OTCDerivativesManagement/riskManagementOfOTCOption/OTCOptionStresstest': {
      component: dynamicWrapper(app, [], () => import('../routes/shareOptionManagement/pressureTest')),
      name: '场外期权压力测试',
    },

    /** -----------------研究管理------------------ */
    '/researchManage/creditSpreadAnalysis': {
      component: dynamicWrapper(app, [], () => import('../routes/researchManage/creditSpreadAnalysis')),
      name: '城投债信用利差分析',
    },
    /** -----------------压力测试------------------ */

    // 压力测试/压力测试报告确认
    '/stressTest/stressTestReportConfirm': {
      component: dynamicWrapper(app, [], () => import('../routes/stressTestReportConform')),
      name: '压力测试报告确认',
    },
    // 压力测试/压力测试报告设置
    '/stressTest/stressTestReportSettings': {
      component: dynamicWrapper(app, [], () => import('../routes/stressTestReportSettings')),
      name: '压力测试报告设置',
    },
    // 压力测试/压力测试报告
    '/stressTest/pressureReport': {
      component: dynamicWrapper(app, [], () => import('../routes/pressureReport')),
      name: '压力测试报告',
    },
    // 压力测试/情景分析
    '/stressTest/stressSceneTest': {
      component: dynamicWrapper(app, [], () => import('../routes/stressSceneTest')),
      name: '情景分析',
    },

    /** -----------------不在左侧菜单中的路由（废弃）------------------ */
    // 不在菜单中
    // '/riskMonitor/limitManagemenOld': {
    //   component: dynamicWrapper(app, [], () => import('../routes/InvestmentMonitor/limitManagemen/index')),
    //   name: '限额设置',
    // },
    // 报告服务/人行监管报表信息维护-不在菜单中
    // '/reportingServices/bankSuperviseInfo1': {
    // component: dynamicWrapper(app, [], () => import('../routes/reportingServices/bankSuperviseInfo')),
    //   name: '人行监管报表信息维护',
    // },
    // 绩效分析/组合总览-不在菜单中
    // '/performanceAnalysis/productPandect': {
    // component: dynamicWrapper(app, ['productPandectM'], () => import('../routes/performanceAnalysis/productPandect')),
    //   name: '组合总览',
    // },
    // 不在菜单中
    // '/tradeInstruction/cashOrder': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/CashOrder/index')),
    //   name: '现金指令',
    // },
    // 组合管理/汇总监控-不在菜单中  汇总监控新建初期是给资管平台引用的，主要展示权益类资产和模拟组合的实时收益。虽未使用，但保留功能
    '/portfolioBuild/CollectingMonitoring': {
      component: dynamicWrapper(app, [], () => import('../routes/PortfolioManagement/CollectingMonitoring')),
      name: '汇总监控',
    },
    // 不在菜单中
    // 非标信息维护旧页面-不在菜单中
    // '/SystemManagement/businessMaintenance/nonstandarmaintenance1': {
    // component: dynamicWrapper(app, [], () => import('../routes/Product/nonstandarmaintenance')),
    //   name: '非标信息维护',
    // },

    /** -----------------注释的路由------------------ */

    // 资产拆分/初始拆分
    // '/assetSplit/initialSplit': {
    // component: dynamicWrapper(app, [], () => import('../routes/assetSplit/InitialSplit')),
    //   name: '初始拆分',
    // },
    // 资产拆分/拆分产品管理
    // '/assetSplit/SplitProductManage': {
    //   component: dynamicWrapper(app, [], () => import('../routes/assetSplit/productManage')),
    //   name: '拆分产品管理',
    // },
    // 指令下达/场外基金
    // '/tradeInstruction/fndTrade': {
    // component: dynamicWrapper(app, ['newFundTrade'], () => import('../routes/InvestmentManage/FundTrade1/index')),
    //   name: '场外基金指令',
    // },
    // 指令下达/理财直融
    // '/tradeInstruction/FinaFlocking': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/finaFlockingNew/index')),
    //   name: '理财直融',
    // },
    // 指令下达/非标产品指令
    // '/tradeInstruction/nonstandardOrder': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/nonstandardOrder')),
    //   name: '非标产品指令',
    // },
    // 指令下达/存款指令
    // '/tradeInstruction/depositOrder': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/depositOrderNew')),
    //   name: '存款指令',
    // },
    // 指令下达/港股通指令
    // '/tradeInstruction/HKstock': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/HKstock')),
    //   name: '港股通指令',
    // },
    // 指令下达/债券网下申购指令
    // '/tradeInstruction/bondOfflineSubscriptionInstructions': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/bondOffline')),
    //   name: '债券网下申购指令',
    // },
    // 指令下达/资产管理计划指令
    // '/tradeInstruction/assetsOrder': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/assetsOrder')),
    //   name: '资产管理计划指令',
    // },
    // 指令下达/委外投资指令
    // '/tradeInstruction/outSourcingOrder': {
    // component: dynamicWrapper(app, [], () => import('../routes/InvestmentManage/OutSourcingOrder')),
    //   name: '委外投资指令',
    // },
    // /**库存管理-持仓-质押券管理*/
    // '/inventoryMnt/holdPosition/pledgeManage': {
    // component: dynamicWrapper(app, ['pledgeManage'], () => import('../routes/investmentAndDecision/pledgeManage/pledgeManage')),
    //   name: '质押券管理',
    // },
  };
  // 这里的代码用于根据用户的权限菜单，设置路由权限，但我们现在没有currentUser.resources的返回值，这里也就没有意义
  // const menuJson = (app._models).find(item => item.namespace === 'user').state.currentUser.resources;
  // console.log(menuData)
  // Route configuration data
  // eg. {name,authority ...routerConfig }
  const routerData = {};
  // The route matches the menu
  Object.keys(routerConfig).forEach((path) => {
    // Regular match item name
    // eg.  router /user/:id === /user/chen
    menuUrl.push({ url: path, permission: routerConfig[path].permission });
    // const pathRegexp = pathToRegexp(path);
    // const menuKey = Object.keys(menuData).find(key => pathRegexp.test(`${key}`));
    // let menuItem = {};
    // // If menuKey is not empty
    // if (menuKey) {
    //   menuItem = menuData[menuKey];
    // }
    let router = routerConfig[path];
    // If you need to configure complex parameter routing,
    // https://github.com/ant-design/ant-design-pro-site/blob/master/docs/router-and-nav.md#%E5%B8%A6%E5%8F%82%E6%95%B0%E7%9A%84%E8%B7%AF%E7%94%B1%E8%8F%9C%E5%8D%95
    // eg . /list/:type/user/info/:id
    router = {
      ...router,
      name: router.name,
      // authority: router.authority || menuItem.authority,
    };
    routerData[path] = router;
  });
  return routerData;
};

export { menuUrl, getRouterData };
